home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / prntfrwd.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.7 KB  |  134 lines

  1. ;void  print_forward(strg,field_size);
  2. ;  char  *strg;
  3. ;  unsigned short  field_size;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _time_out:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC  _print_forward
  12. _print_forward proc near
  13.     jmp  short start    ;jmp over local data
  14. delay    dw   ?            ;
  15. target  dw   ?            ;
  16. start:    push bp            ;
  17.     mov  bp,sp        ;set stack frame
  18.     push si            ;
  19.     cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    push ds            ;save DS
  24.     mov  ah,1        ;BIOS func to init prtr
  25.     sub  dx,dx        ;choose LPT1
  26.     int  17h        ;initialize the prtr port
  27.     sub  ax,ax        ;clear AX
  28.     mov  es,ax        ;point ES to 0000:0000
  29.     mov  dx,es:[408h]    ;get LPT1 base address
  30.     mov  _error_code,1    ;1 = printer error
  31.     mov  al,_time_out    ;get _time_out seconds
  32.     cmp  _memory_model,2    ;data near or far?
  33.     jb   A1            ;jump if near
  34.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  35.     jmp  short A2        ;
  36. A1:    mov  si,[bp+4]        ;near case
  37. A2:    or   al,al        ;don't allow zero seconds
  38.     jnz  A3            ;
  39.     mov  al,3        ;default to 3 seconds
  40. A3:    mov  cl,18        ;18 ticks per second
  41.     mul  cl            ;
  42.     mov  cs:delay,ax    ;save count
  43.     sub  cx,cx        ;clear CX
  44.     push si            ;count string length...
  45. A4:    cmp  byte ptr [si],0    ;end of string?
  46.     je   A5            ;jump if so
  47.     inc  si            ;forward string ptr
  48.     inc  cx            ;inc length counter
  49.     jmp  short A4        ;loop
  50. A5:    pop  si            ;restore ptr to start of string
  51.     jcxz L3            ;jump if string null
  52.     mov  ax,[bp+6]        ;Field Size
  53.     or   ax,ax        ;test for zero
  54.     jz   L5            ;quit if zero
  55.     cmp  cx,ax        ;is Strg larger?
  56.     jna  L1            ;jump ahead if not
  57.     mov  cx,ax        ;strg len = field size
  58.     sub  ax,ax        ;clear AX
  59.     mov  [bp+6],ax        ;write 0 chars after strg
  60.     jmp  short L2        ;jump ahead
  61. L1:    sub  ax,cx        ;field size - strg length
  62.     mov  [bp+6],ax        ;save on stack
  63. L2:    mov  al,[si]        ;get a character
  64.     inc  si            ;forward ptr for next time
  65.     call Writeit        ;go write character
  66.     or   ah,ah        ;test for error
  67.     jz   L5            ;quit if error
  68.     loop L2            ;go do next char
  69. L3:    sub  cx,cx        ;clear CX
  70.     mov  cl,[bp+6]        ;number spc to print
  71.     jcxz L5            ;quit if null
  72. L4:    mov  al,' '        ;space char
  73.     call Writeit        ;go print it
  74.     or   ah,ah        ;test for error
  75.     jz   L5            ;quit if error
  76.     loop L4            ;go do next space
  77.     pop  ds            ;
  78.     dec  _error_code    ;0 = no error
  79.     jmp  short L6         ;
  80. L5:    pop  ds            ;
  81. L6:    pop  si            ;
  82.     pop  bp            ;
  83.     cmp  _memory_model,0    ;quit
  84.     jle  quit        ;
  85.     db   0CBh        ;RET far
  86. quit:    ret            ;RET near
  87. _print_forward endp
  88. Writeit    PROC
  89.     out  dx,al        ;send to output data register
  90.     inc  dx            ;forward to status register
  91.     push cx            ;save string counter
  92.     call GetBiosCount    ;get timer reading
  93.     mov  bx,cx        ;make copy
  94.     add  cx,cs:delay    ;add delay count
  95.     cmp  bx,cx        ;if timer doesn't turn over...
  96.     jb   L7            ;go ahead
  97.     mov  cx,cs:delay    ;otherwise, extend delay
  98. L7:    mov  cs:target,cx    ;save target count on stack
  99. Wait:    in   al,dx        ;get status value
  100.     test al,8        ;test for printer error
  101.     jz   Error        ;
  102.     test al,80h        ;test for Printer Ready
  103.     jnz  Ready        ;jump if ready
  104. Error:    call GetBiosCount    ;
  105.     cmp  cx,cs:target    ;compare to target
  106.     jb   Wait        ;    
  107.     pop  cx            ;restore string counter
  108.     mov  ah,0        ;return code for failure
  109.     jmp  short L8        ;return
  110. Ready:    pop  cx            ;restore string counter
  111.     inc  dx            ; output control register
  112.     mov  al,13        ;bits for strobe signal
  113.     out  dx,al        ;send the signal
  114.     dec  al            ;change to strobe OFF
  115.     out  dx,al        ;send the signal
  116.     dec  dx            ;point back to
  117.     dec  dx            ;  base address
  118.     mov  ah,1        ;return code for success
  119. L8:    ret              ;
  120. Writeit    endp
  121. GetBIOSCount PROC
  122.     push dx            ;return value in CX:DX
  123.     push ax            ;
  124.     sub  ah,ah        ;function number
  125.     int  1ah        ;get timer count
  126.     mov  cx,dx        ;low word in CX
  127.     pop  ax            ;
  128.     pop  dx
  129.     ret
  130. GetBIOSCount endp
  131. Writeit    endp
  132. _TEXT    ENDS
  133.     END
  134.